var fun1 = function (name) {
    print('Hi there from Javascript, ' + name);
    return "greetings from javascript";
};

var fun2 = function (object) {
    print("JS Class Definition: " + Object.prototype.toString.call(object));
};

var funJava1 = function () {
    var MyJavaClass = Java.type('com.lpf.nashorn.TestNashorn_1');
    var result = MyJavaClass.funJava1('John Doe');
    print(result);
    // Hi there from Java, John Doe
    // greetings from java
};

var funJava2 = function () {
    var MyJavaClass = Java.type('com.lpf.nashorn.TestNashorn_1');
    MyJavaClass.funJava2(123);      // class java.lang.Integer
    MyJavaClass.funJava2(49.99);    // class java.lang.Double
    MyJavaClass.funJava2(true);     // class java.lang.Boolean
    MyJavaClass.funJava2("hi there");// class java.lang.String
    MyJavaClass.funJava2(new Number(23));// class jdk.nashorn.internal.objects.NativeNumber
    MyJavaClass.funJava2(new Date());// class jdk.nashorn.internal.objects.NativeDate
    MyJavaClass.funJava2(new RegExp());// class jdk.nashorn.internal.objects.NativeRegExp
    MyJavaClass.funJava2({foo: 'bar'});// class jdk.nashorn.internal.scripts.JO4
};

var funJava3 = function () {
    var MyJavaClass = Java.type('com.lpf.nashorn.TestNashorn_1');
    MyJavaClass.funJava3({foo: 'bar', bar: 'foo'});
};


function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getFullName = function() {
        return this.firstName + " " + this.lastName;
    }
}

var funJava4 = function () {
    var MyJavaClass = Java.type('com.lpf.nashorn.TestNashorn_1');
    var person1 = new Person("Peter", "Parker");
    MyJavaClass.funJava4(person1);
    // Full Name is: Peter Parker
};